﻿<UserControl x:Class="SqlMiM.ReportingServices.ReportExportToSharepoint.View"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SqlMiM.ReportingServices.ReportExportPlugin"
    xmlns:conv2="clr-namespace:SqlMiM.ReportingServices.Converters" 
    xmlns:conv="clr-namespace:SqlMiM.Common.Converters;assembly=SqlMiM.Common"
    xmlns:uc="clr-namespace:SqlMiM.Common.UserControls;assembly=SqlMim.Common" 
    MinWidth="400" Loaded="UserControl_Loaded" >

    <UserControl.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/SqlMiM.Common;component/Resources/ControlsTheme.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            
            <conv2:CatalogTypeIconConverter x:Key="CatalogTypeIconConverter" />
            
            <conv:BooleanToVisibilityConverter x:Key="VisibleIfTrue" Inverted="True" Not="False"    />
            <conv:BooleanToVisibilityConverter x:Key="VisibleIfNotTrue" Inverted="True" Not="True"    />

            <Style x:Key="TreeViewContentControlStyle" TargetType="{x:Type ContentControl}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ContentControl}">
                            <Border Name="MainBorder">
                                <Border BorderThickness="0.5,1,0,0" BorderBrush="#6000" Background="#10FFFFFF" CornerRadius="2,3,2,2"  SnapsToDevicePixels="True">
                                    <ContentPresenter Margin="10" />
                                </Border>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="Content" Value="{x:Null}"/>
                            </ControlTemplate.Triggers>

                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsFirstLoad}" Value="true">
                        <Setter Property="Visibility" Value="Collapsed" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsLoadingCatalog}" Value="true">
                        <Setter Property="Visibility" Value="Collapsed" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

        </ResourceDictionary>

    </UserControl.Resources>

    <ScrollViewer x:Name="scroll" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" 
                                  Margin="0,0,0,0" Padding="0" PreviewMouseWheel="scroll_PreviewMouseWheel">

        <StackPanel Orientation="Vertical" >

            <ContentControl Margin="10,10,10,0" VerticalAlignment="Top" >
                <ContentControl.Content>
                    <DockPanel  LastChildFill="True">
                        <TextBlock DockPanel.Dock="Left" Text="Web Service Url:" Margin="10,0,10,0" VerticalAlignment="Center" ></TextBlock>
                        <Button DockPanel.Dock="Right" Cursor="Hand" Margin="10,0,0,0" Command="{Binding RefrehCatalogCommand}" Width="20" MinWidth="0" >
                            <Button.Template>
                                <ControlTemplate>
                                    <Image Source="/Images/arrow_refresh.png" Width="16" VerticalAlignment="Center" />
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                        <Button DockPanel.Dock="Right" Cursor="Hand" Margin="10,0,0,0" Command="{Binding NavigateWebServiceCommand}" Width="20"  MinWidth="0">
                            <Button.Template>
                                <ControlTemplate>
                                    <Image Source="/Images/Zoom.png" Width="16" VerticalAlignment="Center" />
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                        <TextBox Text="{Binding WebServiceUrl, Mode=TwoWay}" VerticalContentAlignment="Center" ></TextBox>
                    </DockPanel>

                </ContentControl.Content>
            </ContentControl>

            <ContentControl Margin="10,10,10,0" VerticalAlignment="Top" Visibility="{Binding IsLoadingCatalog, Converter={StaticResource VisibleIfTrue}}" >
                <ContentControl.Content>
                    <StackPanel VerticalAlignment="Center" Margin="0" Height="20" Orientation="Horizontal"  >
                        <uc:Waiter HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Bottom" Width="20" Height="20" />
                        <TextBlock Text="Loading in progress .."  Margin="10,0,0,0" VerticalAlignment="Center"  />
                    </StackPanel>
                </ContentControl.Content>
            </ContentControl>

            <ContentControl Margin="10,10,10,0" Name="trvCatalog" VerticalAlignment="Top" 
                            Style="{DynamicResource TreeViewContentControlStyle}">
                <ContentControl.Content>
                        <TreeView ItemsSource="{Binding Catalog}" >
                            <!--<TreeView.ItemContainerStyle>
                                <Style TargetType="{x:Type TreeViewItem}">
                                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                                    <Setter Property="FontWeight" Value="Normal" />
                                    <Style.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter Property="FontWeight" Value="Bold" />
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </TreeView.ItemContainerStyle>-->


                            <TreeView.ItemTemplate>
                                <HierarchicalDataTemplate ItemsSource="{Binding Childrens}">
                                    <Grid VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0" Height="20" >
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>

                                        <Image Grid.Column="0" Margin="0,0,5,0" Width="14"  HorizontalAlignment="Right" Source="{Binding Type, Converter={StaticResource CatalogTypeIconConverter}}" />
                                        <TextBlock  Grid.Column="1" Foreground="White"  HorizontalAlignment="Left" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" 
                                       Text="{Binding Name}" />
                                        <CheckBox Grid.Column="2" Focusable="False" IsChecked="{Binding IsChecked}"  VerticalAlignment="Center" />
                                    </Grid>

                                </HierarchicalDataTemplate>
                            </TreeView.ItemTemplate>


                        </TreeView>
                </ContentControl.Content>
            </ContentControl>


            <ContentControl Margin="10,10,10,0" VerticalAlignment="Top" >
                <ContentControl.Content>
                    <DockPanel LastChildFill="True" HorizontalAlignment="Stretch">
                        <TextBlock DockPanel.Dock="Left" Text="Directory output:" Margin="10,0,10,0" VerticalAlignment="Center" ></TextBlock>
                        <Button DockPanel.Dock="Right" Cursor="Hand" Margin="10,0,0,0" Command="{Binding OutputDirectoryCommand}" Width="20" MinWidth="0" >
                            <Button.Template>
                                <ControlTemplate>
                                    <Image Source="/Images/folder_go.png" Width="16" VerticalAlignment="Center" />
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                        <TextBox Text="{Binding OutputDirectory}" IsReadOnly="True" ></TextBox>
                    </DockPanel>
                </ContentControl.Content>
            </ContentControl>

            <ContentControl Margin="10,10,10,0" VerticalAlignment="Top" >
                <ContentControl.Content>
                    <StackPanel Orientation="Horizontal"  FlowDirection="RightToLeft">
                        <Button Content="Export to directory" Width="150"  Margin="10,0,0,0" Command="{Binding WriteCatalogCommand}"  />
                    </StackPanel>

                </ContentControl.Content>
            </ContentControl>

            <ContentControl Margin="10,10,10,0" VerticalAlignment="Top" >
                <ContentControl.Content>
                        <ItemsControl ItemsSource="{Binding ResultWarnings}" >

                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Vertical" />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>

                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <DockPanel LastChildFill="True" Margin="5">
                                        <Image Source="{Binding IconResult}" Width="12" DockPanel.Dock="Right" Margin="0,0,10,0" />
                                        <Image Source="{Binding IconCatalog}" Width="12" DockPanel.Dock="Left" Margin="10,0,0,0" />
                                        <TextBlock Text="{Binding Message}"  DockPanel.Dock="Right" Margin="10,0,0,0" />
                                    </DockPanel>

                                </DataTemplate>
                            </ItemsControl.ItemTemplate>

                        </ItemsControl>
                </ContentControl.Content>
            </ContentControl>
        </StackPanel>


    </ScrollViewer>
</UserControl>
